import React, { useEffect, useState,useImperativeHandle } from 'react'
import { message, Table, Button } from 'antd';
import { Action, AuthButton, TableCard } from 'components';
import { PlusOutlined } from '@ant-design/icons'
import { Partition_GetList ,Partition_Del} from '../service'
const PhysicalPartition = ({setIsModalOpen,setAddType},ref) => {
    const [dataSource, setdataSource] = useState([])

    useEffect(() => {
       Partition_GetData()
    }, [])

    const Partition_GetData = () => { 
        console.log("调用")
        Partition_GetList().then(res => {
            console.log(res)
            setdataSource(res.data)
        })
    }

  useImperativeHandle(ref, () => ({
    Partition_GetData
  }));
    return (
        <div>
            <TableCard
                rowKey="zone_number"
                dataSource={dataSource}
                pagination={false}
                onReload={Partition_GetData}
                actions={[
                    <Button
                        type="primary"
                        icon={<PlusOutlined />}
                        onClick={() => {
                            setAddType("新增物理分区")
                            setIsModalOpen(true)
                        }}
                    >新建</Button>
                ]}
            >
                <Table.Column title="物理区号"  dataIndex="zone_number" />


                <Table.Column width={80} title="操作" render={info => (
                    <Action>
                        <Action.Button danger onClick={()=>{
                            Partition_Del(info.zone_number).then(res=>{
                                Partition_GetData()
                                if(res.code==0){
                                    message.success("删除成功")
                                }else{
                                    message.error("删除失败")
                                }
                            })
                        }}>删除</Action.Button>
                    </Action>
                )} />
            </TableCard>
        </div>
    )
}

export default React.forwardRef(PhysicalPartition)